//
//  BaseViewController.m
//  PTravel
//
//  Created by dllo on 15/11/17.
//  Copyright © 2015年 李涵. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
//    一、旋转处理
//    第一步：注册通知
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(changeFrames:)
//                                                 name:UIDeviceOrientationDidChangeNotification
//                                               object:nil];
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"states"];
    if ([string isEqualToString:@"1"]) {
        //说明是夜间模式
        self.view.backgroundColor = [UIColor colorWithWhite:0.251 alpha:1.000];
        
    }else{
        self.view.backgroundColor =  [UIColor colorWithWhite:0.902 alpha:1.000];
        
    }
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeToNight:) name:@"night" object:nil];
}

- (void)changeToNight:(NSNotification *)noti{
    UIColor *color = [noti object];//可以不传值,直接写死,黑色
    self.view.backgroundColor = color;
}

//第二把：处理接收事件
-(void)changeFrames:(NSNotification *)notification{
    NSLog(@"change notification: %@", notification.userInfo);
    float width=[[UIScreen mainScreen]bounds].size.width*[[UIScreen mainScreen] scale];
    float height=[[UIScreen mainScreen]bounds].size.height*[[UIScreen mainScreen] scale];
    if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait
        || [[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortraitUpsideDown) {
        NSLog(@">>>portrait");
        self.view.frame=CGRectMake(0, 0, height, width);
    }else{
        NSLog(@">>>landscape");
        self.view.frame=CGRectMake(0, 0, width, height);
    }
    
    NSLog(@"view—> %@",self);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
